package cn.wenhe9.novel.controller.front;

import ch.qos.logback.core.util.FileUtil;
import cn.wenhe9.novel.constant.ApiRouterConsts;
import cn.wenhe9.novel.constant.SystemConfigConsts;
import cn.wenhe9.novel.domain.dto.ImgVerifyCodeDto;
import cn.wenhe9.novel.exception.NovelException;
import cn.wenhe9.novel.result.ResultResponse;
import cn.wenhe9.novel.service.ResourceService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.SneakyThrows;
import org.joda.time.LocalDateTime;
import org.joda.time.format.DateTimeFormat;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import java.util.UUID;

/**
 * 资源（图片/视频/文档）相关接口 API
 *
 * @author DuJinliang
 * 2022/5/18
 */
@Api(tags = "资源（图片/视频/文档）相关 API")
@RestController
@RequestMapping(ApiRouterConsts.API_FRONT_RESOURCE_URL_PREFIX)
public class ResourceController {

    @Resource
    private ResourceService resourceService;

    /**
     * 获取图片验证码接口
     */
    @ApiOperation("获取图片验证码接口")
    @GetMapping("img_verify_code")
    public ResultResponse<ImgVerifyCodeDto> getImgVerifyCode() throws IOException {
        return resourceService.getImgVerifyCode();
    }

    /**
     * 图片上传
     */
    @ApiOperation("图片上传")
    @PostMapping("image")
    ResultResponse<String> upload(@RequestParam("file") MultipartFile file) {
        return resourceService.uploadImg(file);
    }

}
